package com.snow.demo.spring.processor;

import com.snow.demo.spring.entity.DemoBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author -J
 * @since 2024/1/20 20:56
 */
public class DemoBeanBeanPostProcessor implements BeanPostProcessor {
    /**
     * AbstractApplicationContext#finishBeanFactoryInitialization
     *
     * @param bean the new bean instance
     * @param beanName the name of the bean
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof DemoBean){
            System.out.println("BeanPostProcessor->postProcessBeforeInitialization");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof DemoBean){
            System.out.println("BeanPostProcessor->postProcessAfterInitialization");
        }
        return bean;
    }
}
